#include <winsock2.h>

#pragma once

#define MAX_DATA_LENGTH	300
#define DEFAULT_LENTH MAX_DATA_LENGTH
#define DEFAULT_PORT 8093
#define CENTER_LISTENER_PORT	8094
#define CENTER_SPEAKER_PORT		8093
#define CLIENT_LISTENER_PORT	8093
#define CLIENT_SPEAKER_PORT		8094



class WinSocket2Communicator
{
private:
	SOCKET listenerSocket;
	SOCKET speakerSocket;
	sockaddr_in currentSpeakToLocal;
	sockaddr_in currentListenFromLocal;
public:
	WinSocket2Communicator(void);
public:
	~WinSocket2Communicator(void);
public:
	bool initSocket();
	int sendText(SOCKET fd, char* szText, int len);
	int receiveText(SOCKET fd, char* szText, int len);
	int sendTextToSpeaker(char* szText);
	void receiveTextFromListener(char* szText);
	int isListenerSocketOK();
	int setupListenerSocket(u_short port);
	int setupSpeakerSocket(char* szIP, u_short port);
	int connectUsingSpeakerSocket();
	void disconnectUsingSpeakerSocket();
	int bindToPortUsingListenerSocket();
public:
	void setListenerSocket(SOCKET listenerSocket);
	SOCKET getListenerSocket();
	void setSpeakerSocket(SOCKET listenerSocket);
	SOCKET getSpeakerSocket();
protected:
	char szReceivedText[MAX_DATA_LENGTH];
};
